package com.cf.subject.domain.service.impl;

import com.cf.subject.domain.convert.SubjectCategoryConverter;
import com.cf.subject.domain.entity.SubjectCategoryBo;
import com.cf.subject.domain.service.SubjectCategoryDomainService;
import com.cf.subject.infra.basic.entity.SubjectCategory;
import com.cf.subject.infra.basic.service.SubjectCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 乘风破浪
 * @Date: 2024/3/3 10:42
 * @Description:
 **/
@Service
@Slf4j
public class SubjectCategoryDomainServiceImpl implements SubjectCategoryDomainService {
    @Resource
    private SubjectCategoryService categoryService;

    @Override
    public void add(SubjectCategoryBo subjectCategoryBo) {
        if (log.isInfoEnabled()){
            log.info("SubjectController.add.bo{}",subjectCategoryBo);
        }
        //bo 转换未实体类
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.convertBotoCategory(subjectCategoryBo);
        categoryService.save(subjectCategory);
    }

    @Override
    public List<SubjectCategoryBo> queryCategory(SubjectCategoryBo subjectCategoryBo) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.convertBotoCategory(subjectCategoryBo);
        List<SubjectCategory> categoryList = categoryService.queryCategory(subjectCategory);
        return SubjectCategoryConverter.INSTANCE.convertBotoCategory(categoryList);
    }

    @Override
    public boolean updateSubject(SubjectCategoryBo subjectCategoryBo) {
        SubjectCategory subjectCategory = SubjectCategoryConverter.INSTANCE.convertBotoCategory(subjectCategoryBo);
        return categoryService.updateById(subjectCategory);
    }

    @Override
    public boolean deleteSubject(Long id) {
        return categoryService.removeById(id);
    }

}